package apps.web.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import webframe.common.helper.ControllerHelper;
import apps.web.controller.base.MyBaseCommandController;
import apps.web.model.SupervisePlan;
import apps.web.model.User;

public class DeclModifyController extends MyBaseCommandController {

	@Override
	protected ModelAndView handleInner(HttpServletRequest request,
			HttpServletResponse response, Object command)
			throws RuntimeException {
		// declIds
		Long declId = ControllerHelper.extractId(request);

		// opt 操作类型 1=无效单 3=更新ciq查验结果 4=提交报检单监管结果
		int opt = Integer.parseInt(request.getParameter("opt"));
		if (opt == 1) {
			getServiceContainer().getCheckBizService().updateDeclToUnValid(
					declId, ControllerHelper.getUserBySession());
			return null;
		} else if (opt == 3) {
			// getServiceContainer().getCheckBizService().updateDeclResult(declId);
		} else if (opt == 4) {
			Long result = ControllerHelper.extractId(request, "result");
			String remark = request.getParameter("remark");
			SupervisePlan supervisePlan = new SupervisePlan();
			supervisePlan.setResult(result);
			supervisePlan.setRemark(remark);
			supervisePlan.setUpdatedTime(new Date());
			supervisePlan
					.setUserid(((User) ControllerHelper.getUserBySession())
							.getId());
			getServiceContainer().getCheckBizService().updateMainSupervisePlan(
					declId, supervisePlan);

		}

		return new ModelAndView(new RedirectView("DeclView.html?id=" + declId));
	}

}
